package com.epfresh.bean;

import com.epfresh.utils.TimeStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zhaozhenqiang on 2017/7/14.
 */

public class OfferDtoBean {

    /**
     * createTime : 2018-07-09 14:07:10
     * offerProductId : 5146
     * count : 66.0
     * status : 1
     * productOfferDetailsId : 311
     * success : true
     * overTime
     */
    private boolean lastBuyFiveFlag;

    public boolean isLastBuyFiveFlag() {
        return lastBuyFiveFlag;
    }

    public void setLastBuyFiveFlag(boolean lastBuyFiveFlag) {
        this.lastBuyFiveFlag = lastBuyFiveFlag;
    }


    public long getNowTime() {
        return System.currentTimeMillis();
    }

    public String getOfferSellRemindTime() {

        if (overTime != null) {
            long tEnd = TimeStringUtils.formatTimeLong(overTime);
            //tEnd += getOfferDuration()*60*1000;
            //tEnd += 60 * askWaitTime;
            if((tEnd - getNowTime()) / 1000<300){
                setLastBuyFiveFlag(true);
            }
            return getRightTime(tEnd);
        }
        return "";
    }

    public String getOfferBuyRemindTime() {
        if(createTime == null) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            createTime = (df.format(new Date()));
        }
        if (createTime != null) {
            long tEnd = TimeStringUtils.formatTimeLong(overTime);
            //tEnd += 60*1000 * askWaitTime;
            return getRightTime(tEnd);
        }
        return "";
    }

    private String getRightTime(long tEnd) {
        long tLocale = getNowTime();
        long nowRemindTime;
        if (tLocale <= tEnd) {//活动进行中
            nowRemindTime = (tEnd - tLocale) / 1000;
            String timeFlag;
            if (nowRemindTime > 60) {
                long hour = nowRemindTime / 3600;
                long minus = nowRemindTime % 3600 / 60;
                long sec = nowRemindTime % 60;
                if (hour < 10) {
                    timeFlag = "";//"0" + hour;


                    if (minus < 10) {
                        timeFlag += "0" + minus;
                    } else {
                        timeFlag += "" + minus;
                    }
                    if (sec < 10) {
                        timeFlag += ":0" + sec;
                    } else {
                        timeFlag += ":" + sec;
                    }

                } else {
                    timeFlag = "" + hour;

                    if (minus < 10) {
                        timeFlag += ":0" + minus;
                    } else {
                        timeFlag += ":" + minus;
                    }
                    if (sec < 10) {
                        timeFlag += ":0" + sec;
                    } else {
                        timeFlag += ":" + sec;
                    }

                }
                return timeFlag;


            } else if (nowRemindTime > 0) {
                if (nowRemindTime < 10) {
                    timeFlag = "00:0" + nowRemindTime;
                } else {
                    timeFlag = "00:" + nowRemindTime;
                }
                return timeFlag;
            }else
                return "00:00";
        } else
            return "00:00";
    }


    private String overTime;
    private String createTime;
    private String offerProductId;
    private double count;
    private int status;
    private String productOfferDetailsId;
    private boolean success;
    private String price;
    private String startTime;
    private String text;

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getOverTime() {
        return overTime;
    }

    public void setOverTime(String overTime) {
        this.overTime = overTime;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getOfferProductId() {
        return offerProductId;
    }

    public void setOfferProductId(String offerProductId) {
        this.offerProductId = offerProductId;
    }

    public double getCount() {
        return count;
    }

    public void setCount(double count) {
        this.count = count;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getProductOfferDetailsId() {
        return productOfferDetailsId;
    }

    public void setProductOfferDetailsId(String productOfferDetailsId) {
        this.productOfferDetailsId = productOfferDetailsId;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}
